import { Body, Controller, Get, Post, Query, UseGuards } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { Roles } from "/@/logical/adminModule/auth/roles.decorator";
import {
  AddGoodsTypeDto,
  DelGoodsTypeDto,
  EditGoodsTypeDto,
  GetGoodsTypeByPidDto,
  GetGoodsTypeDto,
} from "../dto/goodsType.dto";
import { GoodsTypeService } from "../service/goodsType.service";
import { AuthEnum } from "/@/enum/auth.enum";
import { RolesGuard } from "/@/logical/adminModule/auth/roles.guard";

@ApiTags("goodsType")
@Controller("goodsType")
@UseGuards(RolesGuard)
export class GoodsTypeController {
  constructor(private readonly goodsTypeService: GoodsTypeService) {
    //
  }

  @Get("getGoodsTypeList")
  @Roles(AuthEnum.GOODS, AuthEnum.GOODS_VIEW)
  @ApiOperation({ summary: "获取商品分类列表" })
  async getGoodsTypeList(@Query() query: GetGoodsTypeDto): Promise<any> {
    return this.goodsTypeService.getGoodsTypeList(query);
  }

  @Get("getGoodsTypeListByPid")
  @Roles(AuthEnum.GOODS)
  @ApiOperation({ summary: "根据父级id获取商品分类列表-不分页" })
  async getGoodsTypeListByPid(
    @Query() query: GetGoodsTypeByPidDto,
  ): Promise<any> {
    return this.goodsTypeService.getGoodsTypeListByPid(query);
  }

  @Post("addGoodsType")
  @Roles(AuthEnum.GOODS)
  @ApiOperation({ summary: "添加商品类型" })
  async addGoodsType(@Body() params: AddGoodsTypeDto): Promise<any> {
    return this.goodsTypeService.addGoodsType(params);
  }

  @Post("editGoodsType")
  @Roles(AuthEnum.GOODS)
  @ApiOperation({ summary: "编辑商品类型" })
  async editGoodsType(@Body() params: EditGoodsTypeDto): Promise<any> {
    return this.goodsTypeService.editGoodsType(params);
  }

  @Post("delGoodsType")
  @Roles(AuthEnum.GOODS)
  @ApiOperation({ summary: "删除商品类型" })
  async delGoodsType(@Body() params: DelGoodsTypeDto): Promise<any> {
    return this.goodsTypeService.delGoodsType(params);
  }
}
